package chapter01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Slf4j
public class FutureTaskTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                // 执行方法
                Thread.sleep(2000);
                log.info("任务方法执行了...");

                return 1+1;
            }
        });

        new Thread(futureTask).start();
        log.info("同步等待获取结果...");
        Object res = futureTask.get();
        log.info("获取到的结果如下:{}",res);
    }
}
